function JSONP({
  url,
  params = {},
  callbackKey = 'cb',
  callback
}) {
  JSONP.callbackId = JSONP.callbackId || 1
  let callbackId = JSONP.callbackId

  JSONP.callbacks = JSONP.callbacks || []
  JSONP.callbacks[callbackId] = callback

  params[callbackKey] = `JSONP.callbacks[${callbackId}]`

  const paramString = Object.keys(params).map(key => {
    return `${key}=${encodeURIComponent(params[key])}`
  }).join('&')

  const script = document.createElement('script')
  script.setAttribute('src', `${url}?${paramString}`)
  document.body.appendChild(script)

  JSONP.callbackId++
}